//
//  EpointPhoneViewController.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-5-22.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "EpointPhoneViewController.h"
#import "DBFrameService.h"

@interface EpointPhoneViewController ()

@end

@implementation EpointPhoneViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

-(id)initWithParams:(NSMutableDictionary*)params
{
    self = [super init];
    if (self) {
        intentParams = [params retain];
    }
    return self;
}

-(NSMutableDictionary *)getPassDictionary
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [params setObject:self forKey:@"context"];
    [params setObject:@"Epoint_WebSerivce_**##0601" forKey:@"ValidateData"];
    [params setObject:@"iphone" forKey:@"device"];
//    [params setObject:@"http://192.168.200.131/FGTestWebservice/OAWebService.asmx" forKey:@"url"];
    [params setObject:[DBFrameService getConfigValue:EP_ConfigKey_wsurl] forKey:@"url"];
    [params setObject:@"http://tempuri.org/" forKey:@"namespace"];
    [params setObject:[DBFrameService getConfigValue:EP_ConfigKey_userguid] forKey:@"userguid"];
    return params;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
//    UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
//	temporaryBarButtonItem.title = @"返回";
//    self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
    self.customBackground = [[UIImageView alloc] initWithFrame:self.view.frame];
    [ self.customBackground setImage:[UIImage imageNamed:@"mainbg.jpg"]];
    [ self.customBackground setContentMode:UIViewContentModeScaleAspectFill];
    [self.view addSubview: self.customBackground];
    [self.view sendSubviewToBack: self.customBackground];
//    [self.customBackground removeFromSuperview];
    
    
    NSString *title = [intentParams objectForKey:@"viewtitle"];
    if (title!=nil) {
        self.title = title;
    }
//    [self setWantsFullScreenLayout:YES];
//    [[UIApplication sharedApplication]
//     setStatusBarHidden:YES
//     withAnimation:UIStatusBarAnimationNone];
    
//    self.navigationController.view.frame = CGRectMake(0, 0, 320, 44);
    
    UIButton* backButton= [[UIButton alloc] initWithFrame:CGRectMake(0,0,40,20)];
    [backButton setBackgroundImage:[UIImage imageNamed:@"top_back"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    [leftBarButtonItem release];
    [backButton release];
}

-(void)popBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(BOOL)validateXML:(NSString *)xml
{
    NSString *ReturnInfo = [[StringUtil getXMLFormatedAttribute:xml :@"ReturnInfo"]retain];
    NSString *Status = [StringUtil getXMLFormatedAttribute:xml :@"Status"];
    if ([Status.lowercaseString isEqualToString:@"true"]) {
        return YES;
    }
    else
    {
        [UITool toast:ReturnInfo];
        return NO;
    }
}
-(void)openFileFromSecondApp:(NSString *)_path
{
    UIDocumentInteractionController *documentController =
    [UIDocumentInteractionController
     interactionControllerWithURL:[NSURL fileURLWithPath:_path]];
    documentController.delegate = self;
    [documentController retain];
    //documentController.UTI = @"com.microsoft.word.doc";
    [documentController presentOptionsMenuFromRect:CGRectZero inView:self.view  animated:YES];
}

-(void)showMBPHUD
{
    MBPHUD = [[MBProgressHUD alloc]initWithView:self.view];
	[self.view addSubview:MBPHUD];
    MBPHUD.delegate = self;
    [MBPHUD show:YES];
}

-(void)showMBPHUDWithMessage:(NSString *)_message
{
    MBPHUD = [[MBProgressHUD alloc]initWithView:self.view];
	[self.view addSubview:MBPHUD];
    MBPHUD.delegate = self;
    MBPHUD.labelText = _message;
    [MBPHUD show:YES];
}

-(void)hideMBPHUD
{
    if(![MBPHUD isHidden]){
        [MBPHUD hide:YES];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)viewDidUnload
{
    [intentParams release];
    [ self.customBackground release];
}

@end
